package com.base.mine.presenter;

import android.app.Activity;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.bean.RoadEntity;
import com.base.commonlib.event.RoadEvent;
import com.base.commonlib.utils.MineRoadUtil;
import com.base.commonlib.utils.RxBus2;
import com.base.mine.view.MineRoadView;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by weikailiang on 2019/6/11.
 */

public class MineRoadPresenter extends BasePresenter<MineRoadView> {
    public List<RoadEntity> mRoads=new ArrayList<>();
    public MineRoadPresenter(MineRoadView view, Activity activity) {
        super(view, activity);
    }

    @Override
    public void start() {
        super.start();
        getMineRoads();
        Disposable disposable = RxBus2.getInstance().doSubscribe(RoadEvent.class, new Consumer<RoadEvent>() {
            @Override
            public void accept(RoadEvent roadEvent) throws Exception {
                getMineRoads();
            }
        });
        RxBus2.getInstance().addSubscription(this,disposable);
    }
    public void getMineRoads() {
        List<RoadEntity> mineRoads = MineRoadUtil.getMineRoads(mUser.getUserId());
        mRoads.clear();
        mRoads.addAll(mineRoads);
        mView.showMineRoads();
    }

    @Override
    public void release() {
        super.release();
        RxBus2.getInstance().unSubscribe(this);
    }
}
